import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mtf/app/modules/bank_add_module/bank_add_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';
import 'package:mtf/app/theme/app_text_theme.dart';
import 'package:mtf/app/widget/AppBarLeftTitle.dart';

import '../../../R.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class bank_addPage extends GetView<bank_addController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarLeftTitle(title: "添加银行卡"),
      body: Container(
        width: double.infinity,
        child: ListView.builder(itemBuilder: (context,index){
          if(index==0){
           return Padding(
             padding: const EdgeInsets.symmetric(horizontal: 15,vertical: 10),
             child: Text("请绑定持卡人本人的银行卡",style: TextStyle(fontSize: 12,color: c_999999),),
           );
          }else if(index==1){
            return Container(
              width: double.infinity,
              padding: EdgeInsets.symmetric(horizontal: 10),
              margin: EdgeInsets.symmetric(horizontal: 10),
              decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.circular(10)),
              child: Column(
                children: [
                  // Flex(
                  //   direction: Axis.horizontal,
                  //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  //   children: [
                  //     Text("持卡人",style: leftInputTextStyle,),
                  //     Expanded(
                  //       flex: 1,
                  //       child: TextField(
                  //         textAlign: TextAlign.right,
                  //         decoration: InputDecoration(
                  //             hintText: "请输入持卡人名字",
                  //             hintStyle:
                  //             TextStyle(fontSize: 14, color: c_bbbbbb),
                  //             border: InputBorder.none,),
                  //         style: TextStyle(color: c_333333, fontSize: 14),
                  //         controller: controller.bankNameController,
                  //       ),
                  //     )
                  //   ],
                  // ),
                  // Divider(height: 1,),
                  // Flex(
                  //   direction: Axis.horizontal,
                  //   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  //   children: [
                  //     Text("身份证",style: leftInputTextStyle),
                  //     Expanded(
                  //       flex: 1,
                  //       child: TextField(
                  //         textAlign: TextAlign.right,
                  //         decoration: InputDecoration(
                  //           hintText: "请填写身份证",
                  //           hintStyle:
                  //           TextStyle(fontSize: 14, color: c_bbbbbb),
                  //           border: InputBorder.none,),
                  //         style: TextStyle(color: c_333333, fontSize: 14),
                  //         controller: controller.bankNameController,
                  //       ),
                  //     )
                  //   ],
                  // ),
                  // Divider(height: 1,),
                  Flex(
                    direction: Axis.horizontal,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text("卡号",style: leftInputTextStyle),
                      Expanded(
                        flex: 1,
                        child: TextField(
                          textAlign: TextAlign.right,
                          decoration: InputDecoration(
                            hintText: "请填写卡号",
                            hintStyle:
                            TextStyle(fontSize: 14, color: c_bbbbbb),
                            border: InputBorder.none,),
                          style: TextStyle(color: c_333333, fontSize: 14),
                          controller: controller.bankNumController,
                        ),
                      )
                    ],
                  ),
                  Divider(height: 1,),
                  Flex(
                    direction: Axis.horizontal,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text("开户行",style: leftInputTextStyle),
                      Expanded(
                        flex: 1,
                        child: TextField(
                          textAlign: TextAlign.right,
                          decoration: InputDecoration(
                            hintText: "请填写开户行",
                            hintStyle:
                            TextStyle(fontSize: 14, color: c_bbbbbb),
                            border: InputBorder.none,),
                          style: TextStyle(color: c_333333, fontSize: 14),
                          controller: controller.bankAddressController,
                        ),
                      )
                    ],
                  ),
                  Container(
                    alignment: Alignment.center,
                    padding: const EdgeInsets.symmetric(vertical: 15),
                    child: Text("上传银行卡正面照片"),
                  ),
                  Row(
                    children: [
                      Expanded(
                        flex: 1,
                        child: InkWell(
                          onTap: () {
                            photoDialog();
                          },
                          child: Obx(() {
                            return Column(
                              children: [
                                controller.bankFontBack.value.isEmpty ?
                                Image.asset(
                                  R.assetsImgBgBankFont,
                                  width: double.infinity,
                                  height: 120,
                                ) :
                                Image.network(
                                  controller.bankFontBack.value,
                                  width: double.infinity,
                                  height: 120,
                                ),
                                Padding(
                                  padding:
                                  const EdgeInsets.symmetric(vertical: 10),
                                  child: Text("银行卡正面照"),
                                )
                              ],
                            );
                          }),
                        ),
                      ),
                      Expanded(
                        flex: 1,
                        child: Container(),
                      )
                    ],
                  ),
                ],
              ),
            );
          }else{
            return Container(
              margin: const EdgeInsets.only(top: 30, left: 10, right: 10),
              width: double.maxFinite,
              height: 48,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(24),
                color: c_f12f38,
              ),
              child: TextButton(
                  child: Text("提交",
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 16,
                          fontWeight: FontWeight.bold)),
                  onPressed: () {
                    controller.reqAddBank();
                  }),
            );
          }
        },itemCount: 3,shrinkWrap: true,),
      ),
    );
  }

  void photoDialog() {
    showGeneralDialog<String>(
        context: Get.context!!,
        barrierLabel: '',
        barrierDismissible: false,
        barrierColor: Colors.black.withOpacity(0.2),
        pageBuilder: (context, animation, secondaryAnimation) {
          return Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              height: 171,
              color: Colors.transparent,
              margin: EdgeInsets.only(left: 15, right: 15), //控制底部的距离
              child: Column(
                children: <Widget>[
                  Container(
                    height: 101,
                    decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(10.0),
                    ),
                    child: Column(
                      children: <Widget>[
                        InkWell(
                          onTap: () {
                            controller.selectCamera();
                          },
                          child: Container(
                            height: 50,
                            child: Center(
                              child: Text(
                                '拍照',
                                style: TextStyle(
                                    color: c_333333,
                                    letterSpacing: 2.0,
                                    fontWeight: FontWeight.w200),
                              ),
                            ),
                          ),
                        ),
                        Divider(height: 1),
                        InkWell(
                          onTap: () {
                            controller.selectImage();
                          },
                          child: Container(
                            height: 50,
                            child: Center(
                              child: Text(
                                '本地相册',
                                style: TextStyle(
                                    color: c_333333,
                                    letterSpacing: 2.0,
                                    fontWeight: FontWeight.w200),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  InkWell(
                    onTap: () {
                      Get.back();
                    },
                    child: Container(
                      margin: EdgeInsets.only(
                        top: 10,
                        bottom: 10,
                      ),
                      height: 50,
                      decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(10.0),
                      ),
                      child: Center(
                        child: Text(
                          '取消',
                          style: TextStyle(
                              color: c_808080,
//                          fontSize: Config.fontSize17,
                              fontWeight: FontWeight.w200),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }
}
